Skip to content

Add FORCE_SQLITE Toggle to Avoid Database Conflicts #334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jimboswankster
Copy link

Description:
This pull request introduces a FORCE_SQLITE toggle to address database conflicts when using PraisonAI in environments where Supabase or PostgreSQL databases are active. Additionally, it includes a README update and an optional patch system for ease of use in similar situations.

Here’s a well-formatted description for your pull request:


Title:

Add FORCE_SQLITE Toggle to Avoid Database Conflicts


Description:

This pull request introduces a FORCE_SQLITE toggle to address database conflicts when using PraisonAI in environments where Supabase or PostgreSQL databases are active. Additionally, it includes a README update and an optional patch system for ease of use in similar situations.


Changes:

  1. FORCE_SQLITE Toggle in db.py

    • A new toggle variable (FORCE_SQLITE) has been added to the praisonai/ui/db.py file.
    • When set to True, PraisonAI will bypass the detection of Supabase/Postgres and exclusively use SQLite as the database backend.
    • This resolves schema conflicts caused by incompatible users table definitions between PraisonAI and production applications.
    • This is a necessary feature for data security and safety during production.
    • Separation of concerns: keep the real db safe, while working with the praisonAi [code] tool.
  2. Enhanced Logging

    • Added informative logging to indicate whether the SQLite mode is being forced or a database URL is being detected.
  3. Patch System Directory

    • Created a codePatches directory with a copy of the patched db.py for users who might need to apply similar fixes without editing the source directly.
    • Added a README file to explain the purpose and usage of these patches.
  4. Updated .gitignore

    • Ensured virtual environments and unnecessary files are ignored in the repository.
  5. Documentation

    • Updated the praisonai/ui/README.md file to include an explanation of the FORCE_SQLITE feature and how to enable it.

Why This Change Is Necessary:

  • Problem: In environments where both PraisonAI and a production application share the same .env file, PraisonAI prioritizes Supabase/Postgres connections over SQLite. This leads to schema conflicts, particularly with the users table.
  • Solution: By adding the FORCE_SQLITE toggle, users can explicitly direct PraisonAI to use a local SQLite database, ensuring separation between production databases and the tool's data needs.

How to Use:

  1. Set FORCE_SQLITE = True in praisonai/ui/db.py.
  2. Ensure the .env file does not interfere with this behavior.
  3. Run PraisonAI as usual; it will now use SQLite exclusively.

Notes for Maintainers:

  • If centralizing configuration (e.g., toggles like FORCE_SQLITE) is desirable, I am happy to contribute a separate PR to introduce a centralized config system.
  • If this patch is accepted, consider documenting the FORCE_SQLITE toggle in the primary documentation for broader user awareness.

Testing:

  • Tested in an environment with conflicting database schemas (Supabase + PraisonAI) and confirmed that enabling the FORCE_SQLITE toggle successfully isolated PraisonAI to SQLite.

Let me know if there are any additional adjustments you'd like me to make! It is my opinion that this would be well suited for a centralized config file where the user can select whichever database they want used instead of having auto-detect, or in addition to having autodetect.


I love you work!

@MervinPraison
Copy link
Owner

@claude review this and propose a solution

1 similar comment
@MervinPraison
Copy link
Owner

@claude review this and propose a solution

Copy link
Contributor

claude bot commented May 23, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

@MervinPraison
Copy link
Owner

@claude review and if this issue is a valid issue fix it

Copy link
Contributor

claude bot commented May 23, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

1 similar comment
Copy link
Contributor

claude bot commented May 23, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

@MervinPraison MervinPraison requested a review from Copilot May 24, 2025 05:55
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a FORCE_SQLITE toggle to the database configuration to avoid conflicts when using Supabase/Postgres in production, enhances logging, and provides an optional patch system with documentation updates.

  • Introduces FORCE_SQLITE in db.py and its counterpart copy in codePatches.
  • Adds detailed logging for connection decisions.
  • Updates the README and .gitignore and provides a patch directory with supporting documentation.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
praisonai/ui/db.py Adds FORCE_SQLITE toggle, conditional DB URL selection, and logging.
praisonai/ui/README.md Updates documentation to explain the new toggle functionality.
codePatches/praisonai/ui/db.py Provides a patched copy reflecting FORCE_SQLITE toggle usage.
codePatches/README Documents instructions for applying the patch.
PraisonAI.code-workspace Updates workspace configuration to include the patch directory.

Comment on lines +79 to +83
# Without an option for toggling this on or off this easily causes conflicts, and is intrusive
# self.database_url = os.getenv("DATABASE_URL")
# supabase_url = os.getenv("SUPABASE_DATABASE_URL")
# if supabase_url:
# self.database_url = supabase_url
Copy link
Preview

Copilot AI May 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing the commented-out code block (lines 79-83) if it is no longer necessary to reduce clutter and improve maintainability.

Suggested change
# Without an option for toggling this on or off this easily causes conflicts, and is intrusive
# self.database_url = os.getenv("DATABASE_URL")
# supabase_url = os.getenv("SUPABASE_DATABASE_URL")
# if supabase_url:
# self.database_url = supabase_url
# (No replacement lines; the block is removed entirely.)

Copilot uses AI. Check for mistakes.

cd /path/to/venvPraison/lib/python3.11/site-packages/

1. codePatches/praisonai/ui/db.py
- fixes error where praisonAi tries to gain access to supabase or postgres isntance of production code. this is disallowed because of a table conflict in the [users] table where an either or relationship is caused by conflict schema between the two applications prismScape and praisonAi
Copy link
Preview

Copilot AI May 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the spelling of 'isntance' to 'instance' in this line for clarity.

Suggested change
- fixes error where praisonAi tries to gain access to supabase or postgres isntance of production code. this is disallowed because of a table conflict in the [users] table where an either or relationship is caused by conflict schema between the two applications prismScape and praisonAi
- fixes error where praisonAi tries to gain access to supabase or postgres instance of production code. this is disallowed because of a table conflict in the [users] table where an either or relationship is caused by conflict schema between the two applications prismScape and praisonAi

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants